import { h, ref, reactive } from 'vue'
import TableAction from '@/components/DataTable/tools/Action.vue'
import TableImage from '@/components/DataTable/tools/Image.vue'
import { useUserStore } from '@/store/modules/user'
import { router } from '@/router/index'
import { getReportDetail, getReportHandleDetail } from '@/api/report/index'

const roleType = ref(null)
setTimeout(() => {
  roleType.value = useUserStore().userInfo.type
})

/* 注册table */
const tableRef = ref()
const searchParams = ref()

function handleSearch(params) {
  searchParams.value = {
    name: params?.name,
    beginTime: params?.taskTime?.[0],
    endTime: params?.taskTime?.[1],
    status: 15
  }
  tableRef.value.reFetch({ searchParams })
}

/**
 * @description: 详情
 * @param {*} row 单行数据
 * @param {*} type 操作类型 create:创建，preview:预览，edit:编辑
 * @return {*}
 */
async function getRowData(row, type) {
  router.push({
    path: '/home',
    query: {
      type: type,
      taskId: row?.id
    }
  })
}

const data = reactive({
  tableRef,
  searchParams,
  rowData: {},
  modalType: 'create',
  modalShow: false,
  showDraw: false,
  detail: {},
  handleSearch,
  columns: [
    {
      title: '序号',
      key: 'key',
      render: (_, index) => {
        return `${index + 1}`
      },
      align: 'center',
      width: 100
    },
    {
      title: '任务名称',
      key: 'name',
      align: 'center'
    },
    {
      title: '任务时间',
      key: 'executionStartTime',
      align: 'center'
    },
    {
      title: '机场',
      key: 'airportName',
      align: 'center'
    },
    {
      title: '操作',
      align: 'center',
      key: 'actionBtn',
      fixed: 'right',
      disabled: false,
      render(row) {
        return h(TableAction, {
          actions: [
            {
              label: '监测报告',
              type: 'button',
              props: {
                type: 'primary',
                text: true,
                onClick: getRowData.bind(null, row, 'preview')
              },
              auth: 'report:list:check-report',
              show: row.status === 15
            },
            {
              label: '数据下载',
              type: 'button',
              props: {
                type: 'primary',
                text: true,
                onClick: getRowData.bind(null, row, 'preview')
              },
              auth: 'report:list:download-report',
              show: row.status === 15
            }
          ],
          align: 'center'
        })
      }
    }
  ]
})

export default data
